﻿Imports System.IO
Imports System.Windows.Forms.Help
Public Class Frm_Admin

    Private Sub Frm_Admin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lbUserName.Text = Frm_Login.username + " (" + Frm_Login.acctype + ")"
        TabAdmin.SelectedTab = tabChucNangThem
        rdTimMaVe.Checked = True
        cbxLoaiVe.Text = "Tất cả"

        gvNhanVien_Load()
        ComboBox_Load()
        rdNam.Checked = True
        rdTimTheoTen.Checked = True
        rdTimTenTV.Checked = True
        rdTimTenPhim.Checked = True
        rbMaSuatChieu.Checked = True
        gvThanhVien_Load()
        gvPhongChieu_Load()
        gvPhim_Load()
        gvQLSuatChieu_Load()
        gvCaChieu_Load()
        cmbTinhTrang.Text = "Hoạt động"
        cmbXemTheoPhim.Text = "Tất cả"
        cbxNgayChieu.Text = "Tất cả"
        gvVe_Load()
        lbSLVe.Text = gvVe.RowCount - 1
    End Sub
    Private Sub TabPage1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TabPage1.Click

    End Sub

    Private Sub Label17_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Label17.Click

    End Sub


    Private Sub ComboBox_Load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        cmbChucVu.DataSource = bus.GetTable("select * from CHUCVU")
        cmbChucVu.DisplayMember = "TenChucVu"
        cmbChucVu.ValueMember = "MaChucVu"
        cmbLoaiNV.DataSource = bus.GetTable("select * from CHUCVU")
        cmbLoaiNV.DisplayMember = "TenChucVu"
        cmbLoaiNV.ValueMember = "MaChucVu"
        cmbMaRap.DataSource = bus.GetTable("select * from RAP")
        cmbMaRap.DisplayMember = "MaRap"
        cmbMaRap.ValueMember = "MaRap"
        cmbXemTheoRap.DataSource = bus.GetTable("select * from RAP")
        cmbXemTheoRap.DisplayMember = "MaRap"
        cmbXemTheoRap.ValueMember = "MaRap"
        cbxTenPhim.DataSource = bus.GetTable("select * from PHIM")
        cbxTenPhim.DisplayMember = "TenPhim"
        cbxTenPhim.ValueMember = "TenPhim"
        cbxQLTenPhim.DataSource = bus.GetTable("select * from PHIM")
        cbxQLTenPhim.DisplayMember = "TenPhim"
        cbxQLTenPhim.ValueMember = "TenPhim"
        cbxMaCaChieu.DataSource = bus.GetTable("select * from CACHIEU")
        cbxMaCaChieu.DisplayMember = "MaCaChieu"
        cbxMaCaChieu.ValueMember = "MaCaChieu"
        cbxMaPhongChieu.DataSource = bus.GetTable("select * from PHONGCHIEU")
        cbxMaPhongChieu.DisplayMember = "MaPhongChieu"
        cbxMaPhongChieu.ValueMember = "MaPhongChieu"
        cbxNgayChieu.DataSource = bus.GetTable("select * from SUATCHIEU")
        cbxNgayChieu.DisplayMember = "NgayChieu"
        cbxNgayChieu.ValueMember = "NgayChieu"
    End Sub




    Private Sub gvNhanVien_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvNhanVien.SelectionChanged
        Dim bus As NhanVienBUS = New NhanVienBUS()
        Try
            If gvNhanVien.SelectedRows.Count = 0 Then
                Return
            End If
            lbMaNV.Text = gvNhanVien.CurrentRow.Cells(0).Value.ToString()
            txtHoTenNV.Text = gvNhanVien.CurrentRow.Cells(1).Value.ToString()
            If gvNhanVien.CurrentRow.Cells(4).Value.ToString() = "Nu" Then
                rdNu.Checked = True
            Else
                rdNam.Checked = True
            End If
            txtCMND.Text = gvNhanVien.CurrentRow.Cells(2).Value.ToString()
            txtDienThoai.Text = gvNhanVien.CurrentRow.Cells(6).Value.ToString()
            txtDiaChi.Text = gvNhanVien.CurrentRow.Cells(5).Value.ToString()
            txtMatKhau.Text = gvNhanVien.CurrentRow.Cells(8).Value.ToString()
            dtpNgaySinh.Value = gvNhanVien.CurrentRow.Cells(3).Value
            cmbChucVu.Text = bus.GetValue("select TenChucVu from CHUCVU where MaChucVu=" + gvNhanVien.CurrentRow.Cells(7).Value.ToString())
        Catch
        End Try

    End Sub
    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If (txtHoTenNV.Text = "" Or txtCMND.Text = "" Or dtpNgaySinh.Value.Date.ToString() = "" Or txtDiaChi.Text = "" Or txtDienThoai.Text = "" Or cmbChucVu.SelectedValue.ToString() = "" Or txtMatKhau.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim nv As NhanVienDTO = New NhanVienDTO()
            Dim bus As NhanVienBUS = New NhanVienBUS()
            nv.CMND = txtCMND.Text
            nv.HoTenNV = txtHoTenNV.Text
            If (rdNu.Checked = True) Then
                nv.GioiTinh = True
            Else
                nv.GioiTinh = False
            End If
            nv.DiaChi = txtDiaChi.Text
            nv.NgaySinh = dtpNgaySinh.Value.Date
            nv.DienThoai = txtDienThoai.Text
            nv.MaChucVu = cmbChucVu.SelectedValue.ToString()
            nv.MaChucVu = cmbChucVu.SelectedValue.ToString()
            nv.MatKhau = txtMatKhau.Text

            bus.Insert(nv)
            gvNhanVien_Load()
        End If
    End Sub
    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If (txtHoTenNV.Text = "" Or txtCMND.Text = "" Or dtpNgaySinh.Value.Date.ToString() = "" Or txtDiaChi.Text = "" Or txtDienThoai.Text = "" Or cmbChucVu.SelectedValue.ToString() = "" Or txtMatKhau.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim bus As NhanVienBUS = New NhanVienBUS()
            Dim tmp As NhanVienDTO = New NhanVienDTO()
            tmp.MaNhanVien = lbMaNV.Text
            tmp.HoTenNV = txtHoTenNV.Text
            tmp.CMND = txtCMND.Text
            tmp.DienThoai = txtDienThoai.Text
            If (rdNam.Checked = True) Then
                tmp.GioiTinh = False
            Else
                tmp.GioiTinh = True
            End If
            tmp.NgaySinh = dtpNgaySinh.Value.Date
            tmp.DiaChi = txtDiaChi.Text
            tmp.DienThoai = txtDienThoai.Text
            tmp.MatKhau = txtMatKhau.Text
            tmp.MaChucVu = cmbChucVu.SelectedValue.ToString()
            bus.Update(tmp)
            gvNhanVien_Load()
        End If
    End Sub



    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim bus As NhanVienBUS = New NhanVienBUS()
        Dim tmp As NhanVienDTO = New NhanVienDTO()
        tmp.MaNhanVien = lbMaNV.Text
        bus.Delete(tmp)
        gvNhanVien_Load()
    End Sub

    Private Sub cmbLoaiNV_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbLoaiNV.SelectionChangeCommitted
        Dim bus As NhanVienBUS = New NhanVienBUS()
        Dim str As String = ""
        str = "select * from NHANVIEN where MaChucVu=" + cmbLoaiNV.SelectedValue.ToString()
        gvNhanVien.DataSource = bus.GetTable(str)
    End Sub


    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        If (rdTimTheoTen.Checked = True) Then
            Dim bus As NhanVienBUS = New NhanVienBUS()
            Dim str As String = "select * from NHANVIEN where HoTenNV like '%" + txtTimKiem.Text + "%'"
            gvNhanVien.DataSource = bus.GetTable(str)
        ElseIf (rdTimTheoMa.Checked = True) Then
            Dim bus As NhanVienBUS = New NhanVienBUS()
            Dim str As String = "select * from NHANVIEN where MaNV like '%" + txtTimKiem.Text + "%'"
            gvNhanVien.DataSource = bus.GetTable(str)
        End If
    End Sub
    Public Sub gvNhanVien_Load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        gvNhanVien.DataSource = bus.GetTable("select * from NHANVIEN")
    End Sub



    ' Thanh vien:
    '......................................
    '.....................................................
    Public Sub gvThanhVien_Load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        gvThanhVien.DataSource = bus.GetTable("select * from THANHVIEN")
    End Sub

    Private Sub btnThemTV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemTV.Click
        If (txtIDThanhVien.Text = "" Or txtTenTV.Text = "" Or txtDTTV.Text = "" Or txtCMNDTV.Text = "" Or txtMatKhauTV.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim tv As ThanhVienDTO = New ThanhVienDTO()

            Dim bus As ThanhVienBUS = New ThanhVienBUS()

            Dim kt As String = "select * from THANHVIEN where IDThanhVien='" + txtIDThanhVien.Text + "'"
            Dim dt = New DataTable
            dt = bus.GetTable(kt)
            If (dt.Rows.Count = 0) Then
                tv.CMND = txtCMNDTV.Text
                tv.TenThanhVien = txtTenTV.Text
                tv.IDThanhVien = txtIDThanhVien.Text
                If (cbHSSV.Checked = True) Then
                    tv.HSSV = True
                Else
                    tv.HSSV = False
                End If

                tv.SDT = txtDTTV.Text

                tv.MatKhau = txtMatKhauTV.Text

                bus.Insert(tv)
                gvThanhVien_Load()
            Else
                MessageBox.Show("Ten dang nhap da ton tai")
            End If
        End If
    End Sub



    Private Sub gvThanhVien_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvThanhVien.SelectionChanged
        Dim bus As ThanhVienBUS = New ThanhVienBUS()
        Try
            If gvThanhVien.SelectedRows.Count = 0 Then
                Return
            End If
            txtIDThanhVien.Text = gvThanhVien.CurrentRow.Cells(0).Value.ToString()
            txtTenTV.Text = gvThanhVien.CurrentRow.Cells(1).Value.ToString()
            If gvThanhVien.CurrentRow.Cells(5).Value = True Then
                cbHSSV.Checked = True
            Else
                cbHSSV.Checked = False
            End If
            txtCMNDTV.Text = gvThanhVien.CurrentRow.Cells(3).Value.ToString()
            txtDTTV.Text = gvThanhVien.CurrentRow.Cells(2).Value.ToString()
            txtMatKhauTV.Text = gvThanhVien.CurrentRow.Cells(4).Value.ToString()
        Catch
        End Try
    End Sub

    Private Sub btnSuaTV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaTV.Click
        If (txtIDThanhVien.Text = "" Or txtTenTV.Text = "" Or txtDTTV.Text = "" Or txtCMNDTV.Text = "" Or txtMatKhauTV.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim bus As ThanhVienBUS = New ThanhVienBUS()
            Dim tmp As ThanhVienDTO = New ThanhVienDTO()
            tmp.CMND = txtCMNDTV.Text
            tmp.IDThanhVien = txtIDThanhVien.Text
            tmp.MatKhau = txtMatKhauTV.Text
            If (cbHSSV.Checked = True) Then
                tmp.HSSV = True
            Else
                tmp.HSSV = False
            End If
            tmp.SDT = txtDTTV.Text
            tmp.TenThanhVien = txtTenTV.Text
            bus.Update(tmp)
            gvThanhVien_Load()
        End If
    End Sub

    Private Sub btnXoaTV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaTV.Click
        Dim bus As ThanhVienBUS = New ThanhVienBUS()
        Dim tmp As ThanhVienDTO = New ThanhVienDTO()
        tmp.IDThanhVien = txtIDThanhVien.Text
        bus.Delete(tmp)
        gvThanhVien_Load()
    End Sub

    Private Sub cmbXemLoaiTV_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbXemLoaiTV.SelectionChangeCommitted
        Dim bus As ThanhVienBUS = New ThanhVienBUS()
        If (cmbXemLoaiTV.SelectedItem = "HSSV") Then
            Dim str As String = ""
            str = "select * from THANHVIEN where HSSV=true"
            gvThanhVien.DataSource = bus.GetTable(str)
        ElseIf (cmbXemLoaiTV.SelectedItem = "Nomal") Then
            Dim str As String = ""
            str = "select * from THANHVIEN where HSSV=false"
            gvThanhVien.DataSource = bus.GetTable(str)
        ElseIf (cmbXemLoaiTV.SelectedItem = "All") Then
            Dim str As String = ""
            str = "select * from THANHVIEN"
            gvThanhVien.DataSource = bus.GetTable(str)
        End If

    End Sub

    Private Sub btnTimTV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimTV.Click
        If (rdTimTenTV.Checked = True) Then
            Dim bus As ThanhVienBUS = New ThanhVienBUS()
            Dim str As String = "select * from THANHVIEN where TenThanhVien like '%" + txtTimTV.Text + "%'"
            gvThanhVien.DataSource = bus.GetTable(str)
        ElseIf (rdTimIDTV.Checked = True) Then
            Dim bus As ThanhVienBUS = New ThanhVienBUS()
            Dim str As String = "select * from THANHVIEN where IDThanhVien like '%" + txtTimTV.Text + "%'"
            gvThanhVien.DataSource = bus.GetTable(str)
        End If
    End Sub


    ''Phòng Chiếu
    '''''''''''''''''''''''''''''''''''
    Public Sub gvPhongChieu_Load()
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        gvPhongChieu.DataSource = bus.GetTable("select * from PHONGCHIEU")
    End Sub

    Private Sub gvPhongChieu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvPhongChieu.SelectionChanged
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        Try
            If gvPhongChieu.SelectedRows.Count = 0 Then
                Return
            End If
            lbMaPC.Text = gvPhongChieu.CurrentRow.Cells(0).Value.ToString()
            cmbMaRap.Text = bus.GetValue("select MaRap from RAP where MaRap=" + gvPhongChieu.CurrentRow.Cells(1).Value.ToString())
            txtSoDay.Text = gvPhongChieu.CurrentRow.Cells(2).Value.ToString()
            txtSoHang.Text = gvPhongChieu.CurrentRow.Cells(3).Value.ToString()
            txtMoTa.Text = gvPhongChieu.CurrentRow.Cells(4).Value.ToString()
            cmbDKKT.Text = gvPhongChieu.CurrentRow.Cells(5).Value.ToString() 'bus.GetValue("select DKKT from PhongChieu where DKKT=" + gvPhongChieu.CurrentRow.Cells(5).Value.ToString())
            cmbTinhTrang.Text = gvPhongChieu.CurrentRow.Cells(6).Value.ToString() ' bus.GetValue("select TinhTrang from PhongChieu where TinhTrang=" + gvPhongChieu.CurrentRow.Cells(6).Value.ToString())
        Catch
        End Try
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim pc As PhongChieuDTO = New PhongChieuDTO()
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        pc.SoDayGhe = Convert.ToInt32(txtSoDay.Text)
        pc.SoHangGhe = Convert.ToInt32(txtSoHang.Text)
        pc.MaRap = Convert.ToInt32(cmbMaRap.SelectedValue.ToString())
        pc.MoTa = txtMoTa.Text
        pc.DKKT = cmbDKKT.SelectedItem.ToString()
        pc.TinhTrang = cmbTinhTrang.SelectedItem.ToString()
        bus.Insert(pc)
        gvPhongChieu_Load()
    End Sub


    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        Dim tmp As PhongChieuDTO = New PhongChieuDTO()
        tmp.MaPhongChieu = Convert.ToInt32(lbMaPC.Text)
        bus.Delete(tmp)
        gvPhongChieu_Load()
    End Sub


    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        Dim pc As PhongChieuDTO = New PhongChieuDTO()
        pc.MaPhongChieu = lbMaPC.Text
        pc.SoDayGhe = Convert.ToInt32(txtSoDay.Text)
        pc.SoHangGhe = Convert.ToInt32(txtSoHang.Text)
        pc.MaRap = Convert.ToInt32(cmbMaRap.SelectedValue.ToString())
        pc.MoTa = txtMoTa.Text 'roi thu xem
        pc.DKKT = cmbDKKT.SelectedItem.ToString()
        pc.TinhTrang = cmbTinhTrang.SelectedItem.ToString()
        bus.Update(pc)
        gvPhongChieu_Load()
    End Sub

    Private Sub cmbXemTheoRap_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbXemTheoRap.SelectionChangeCommitted
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        Dim str As String = ""
        str = "select * from PhongChieu where MaRap=" + cmbXemTheoRap.SelectedValue.ToString()
        gvPhongChieu.DataSource = bus.GetTable(str)
    End Sub



    'Quan ly phim
    '.........................................


    Public Sub gvPhim_Load()
        Dim bus As PhimBUS = New PhimBUS()
        gvPhim.DataSource = bus.GetTable("select * from PHIM")
    End Sub

    Private Sub gvPhim_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gvPhim.CellContentClick

    End Sub



    Private Sub gvPhim_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvPhim.SelectionChanged
        Dim bus As PhimBUS = New PhimBUS()
        Try
            If gvPhim.SelectedRows.Count = 0 Then
                Return
            End If
            txtTenPhim.Text = gvPhim.CurrentRow.Cells(0).Value.ToString()
            txtGioiThieuPhim.Text = gvPhim.CurrentRow.Cells(1).Value.ToString()
            txtTrailerPhim.Text = gvPhim.CurrentRow.Cells(2).Value.ToString()
            txtPosterPhim.Text = gvPhim.CurrentRow.Cells(3).Value.ToString()
            txtThoiLuongPhim.Text = gvPhim.CurrentRow.Cells(4).Value.ToString()
            txtNamSXPhim.Text = gvPhim.CurrentRow.Cells(5).Value.ToString()
            txtNuocSXPhim.Text = gvPhim.CurrentRow.Cells(6).Value.ToString()
            txtHangPhim.Text = gvPhim.CurrentRow.Cells(7).Value.ToString()
        Catch
        End Try
    End Sub
    Private Sub btnThemPhim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemPhim.Click
        If (txtTenPhim.Text = "" Or txtGioiThieuPhim.Text = "" Or txtTrailerPhim.Text = "" Or txtPosterPhim.Text = "" Or txtThoiLuongPhim.Text = "" Or txtNamSXPhim.Text = "" Or txtNuocSXPhim.Text = "" Or txtHangPhim.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim p As PhimDTO = New PhimDTO()
            Dim bus As PhimBUS = New PhimBUS()
            Dim kt As String = "select * from PHIM where TenPhim='" + txtTenPhim.Text + "'"
            Dim dt = New DataTable
            dt = bus.GetTable(kt)
            If (dt.Rows.Count = 0) Then
                p.TenPhim = txtTenPhim.Text
                p.GioiThieu = txtGioiThieuPhim.Text
                p.Trailer = txtTrailerPhim.Text
                p.Poster = txtPosterPhim.Text
                p.ThoiLuong = txtThoiLuongPhim.Text
                p.NamSX = txtNamSXPhim.Text
                p.NuocSX = txtNuocSXPhim.Text
                p.HangPhim = txtHangPhim.Text
                bus.Insert(p)
                gvPhim_Load()
            Else
                MessageBox.Show("Ten phim da ton tai")
            End If
        End If
    End Sub
    Private Sub btnSuaPhim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaPhim.Click
        If (txtTenPhim.Text = "" Or txtGioiThieuPhim.Text = "" Or txtTrailerPhim.Text = "" Or txtPosterPhim.Text = "" Or txtThoiLuongPhim.Text = "" Or txtNamSXPhim.Text = "" Or txtNuocSXPhim.Text = "" Or txtHangPhim.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim bus As PhimBUS = New PhimBUS()
            Dim tmp As PhimDTO = New PhimDTO()
            tmp.GioiThieu = txtGioiThieuPhim.Text
            tmp.HangPhim = txtHangPhim.Text
            tmp.NamSX = txtNamSXPhim.Text
            tmp.NuocSX = txtNuocSXPhim.Text
            tmp.Poster = txtPosterPhim.Text
            tmp.TenPhim = txtTenPhim.Text
            tmp.ThoiLuong = txtThoiLuongPhim.Text
            tmp.Trailer = txtTrailerPhim.Text
            bus.Update(tmp)
            gvPhim_Load()
        End If
    End Sub

    Private Sub btnXoaPhim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaPhim.Click
        Dim bus As PhimBUS = New PhimBUS()
        Dim tmp As PhimDTO = New PhimDTO()
        tmp.TenPhim = txtTenPhim.Text
        bus.Delete(tmp)
        gvPhim_Load()
    End Sub

    Private Sub btnSetTheLoai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetTheLoai.Click
        Dim QT As frmTheLoaiPhim = New frmTheLoaiPhim()
        QT.ShowDialog()
    End Sub








    Private Sub cmbXemTheoPhim_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbXemTheoPhim.SelectedIndexChanged
        Dim bus As TheLoaiPhimBUS = New TheLoaiPhimBUS()
        Dim str As String = ""
        If cmbXemTheoPhim.Text = "Tất cả" Then
            str = "select  * from PHIM"
            gvPhim.DataSource = bus.GetTable(str)
        Else
            str = "select PHIM.TenPhim, GioiThieu, Trailer, Poster, ThoiLuong, NamSX, NuocSX, HangPhim from PHIM, THELOAIPHIM where TenTheLoai='" + cmbXemTheoPhim.Text + "' and PHIM.TenPhim = THELOAIPHIM.TenPhim"
            gvPhim.DataSource = bus.GetTable(str)
        End If
    End Sub

    Private Sub btnTimPhim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimPhim.Click
        If (rdTimTenPhim.Checked = True) Then
            Dim bus As PhimBUS = New PhimBUS()
            Dim str As String = "select * from PHIM where TenPhim like '%" + txtTimPhim.Text + "%'"
            gvPhim.DataSource = bus.GetTable(str)
        ElseIf (rdTimHangPhim.Checked = True) Then
            Dim bus As PhimBUS = New PhimBUS()
            Dim str As String = "select * from PHIM where HangPhim like '%" + txtTimPhim.Text + "%'"
            gvPhim.DataSource = bus.GetTable(str)
        ElseIf (rdTimNamSX.Checked = True) Then
            Dim bus As PhimBUS = New PhimBUS()
            Dim str As String = "select * from PHIM where NamSX like '%" + txtTimPhim.Text + "%'"
            gvPhim.DataSource = bus.GetTable(str)
        ElseIf (rdTimNuocSX.Checked = True) Then
            Dim bus As PhimBUS = New PhimBUS()
            Dim str As String = "select * from PHIM where NuocSX like '%" + txtTimPhim.Text + "%'"
            gvPhim.DataSource = bus.GetTable(str)
        End If
    End Sub







    'Quan ly ca chieu
    '------------------------------------------------

    Public Sub gvCaChieu_Load()
        Dim bus As CaChieuBUS = New CaChieuBUS()
        gvCaChieu.DataSource = bus.GetTable("select MaCaChieu,hour(cc.GioBatDau)as GioBatDau, Hour(cc.GioKetThuc)as GioKetThuc from CACHIEU cc")
    End Sub

    Private Sub btnThemCaChieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemCaChieu.Click
        If (txtTimeEnd.Text = "" Or txtTimeStar.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim cc As CaChieuDTO = New CaChieuDTO()
            Dim bus As CaChieuBUS = New CaChieuBUS()
            cc.MaCaChieu = qlMachieu.Text
            cc.GioBatDau = txtTimeStar.Text
            cc.GioKetThuc = txtTimeEnd.Text
            bus.Insert(cc)
            gvCaChieu_Load()
        End If
    End Sub

    Private Sub btnXoaCaChieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaCaChieu.Click
        Dim bus As CaChieuBUS = New CaChieuBUS()
        Dim tmp As CaChieuDTO = New CaChieuDTO()
        tmp.MaCaChieu = qlMachieu.Text
        bus.Delete(tmp)
        gvCaChieu_Load()
    End Sub

    Private Sub btnSuaCaChieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaCaChieu.Click
        If (txtTimeEnd.Text = "" Or txtTimeStar.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim bus As CaChieuBUS = New CaChieuBUS()
            Dim cc As CaChieuDTO = New CaChieuDTO()
            cc.MaCaChieu = qlMachieu.Text
            cc.GioBatDau = txtTimeStar.Text
            cc.GioKetThuc = txtTimeEnd.Text
            bus.Update(cc)
            gvCaChieu_Load()
        End If
    End Sub

    Private Sub gvCaChieu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvCaChieu.SelectionChanged
        Dim bus As CaChieuBUS = New CaChieuBUS()
        Try
            If gvCaChieu.SelectedRows.Count = 0 Then
                Return
            End If
            qlMachieu.Text = gvCaChieu.CurrentRow.Cells(0).Value.ToString()
            txtTimeStar.Text = gvCaChieu.CurrentRow.Cells(1).Value.ToString()
            txtTimeEnd.Text = gvCaChieu.CurrentRow.Cells(2).Value.ToString()
        Catch
        End Try
    End Sub






    'Quan ly suat chieu
    '----------------------------------------
    Public Sub gvQLSuatChieu_Load()
        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        gvQLSuatChieu.DataSource = bus.GetTable("select * from SUATCHIEU")
    End Sub
    Private Sub btnThemSC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemSC.Click
        If (cbxMaCaChieu.SelectedValue.ToString() = "" Or cbxTenPhim.SelectedValue.ToString() = "" Or cbxMaPhongChieu.SelectedValue.ToString() = "" Or txtGioBatDau.Text = "" Or txtGioKetThuc.Text = "" Or txtGiaVe.Text = "" Or dtpNgayChieu.Value.Date.ToString() = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim tmp As SuatChieuDTO = New SuatChieuDTO()
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            tmp.MaCaChieu = cbxMaCaChieu.SelectedValue.ToString()
            tmp.GioBatDau = txtGioBatDau.Text()
            tmp.GioKetThuc = txtGioKetThuc.Text()
            tmp.NgayChieu = dtpNgayChieu.Value.Date()
            tmp.TenPhim = cbxTenPhim.SelectedValue.ToString()
            tmp.MaPhongChieu = cbxMaPhongChieu.SelectedValue.ToString()
            tmp.GiaVe = txtGiaVe.Text()
            bus.Insert(tmp)
            gvQLSuatChieu_Load()
        End If
    End Sub

    Private Sub gvQLSuatChieu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvQLSuatChieu.SelectionChanged

        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        Try
            If gvQLSuatChieu.SelectedRows.Count = 0 Then
                Return
            End If

            txtMaSuatChieu.Text = gvQLSuatChieu.CurrentRow.Cells(0).Value.ToString()
            cbxMaCaChieu.Text = gvQLSuatChieu.CurrentRow.Cells(1).Value.ToString()
            txtGioBatDau.Text = gvQLSuatChieu.CurrentRow.Cells(2).Value.ToString()
            txtGioKetThuc.Text = gvQLSuatChieu.CurrentRow.Cells(3).Value.ToString()
            dtpNgayChieu.Value = gvQLSuatChieu.CurrentRow.Cells(4).Value
            cbxTenPhim.Text = gvQLSuatChieu.CurrentRow.Cells(5).Value.ToString()
            cbxMaPhongChieu.Text = gvQLSuatChieu.CurrentRow.Cells(6).Value.ToString()
            txtGiaVe.Text = gvQLSuatChieu.CurrentRow.Cells(7).Value.ToString()
        Catch
        End Try
    End Sub

    Private Sub btnXoaSC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaSC.Click

        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        Dim tmp As SuatChieuDTO = New SuatChieuDTO()
        tmp.MaSuatChieu = txtMaSuatChieu.Text()
        bus.Delete(tmp)
        gvCaChieu_Load()
    End Sub

    Private Sub btnSuaSC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaSC.Click
        If (cmbChucVu.SelectedValue.ToString() = "" Or cbxTenPhim.SelectedValue.ToString() = "" Or cbxMaPhongChieu.SelectedValue.ToString() = "" Or txtGioBatDau.Text = "" Or txtGioKetThuc.Text = "" Or txtGiaVe.Text = "" Or dtpNgayChieu.Value.Date.ToString() = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim tmp As SuatChieuDTO = New SuatChieuDTO()
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            tmp.MaSuatChieu = txtMaSuatChieu.Text
            tmp.MaCaChieu = cbxMaCaChieu.SelectedValue.ToString()
            tmp.GioBatDau = txtGioBatDau.Text()
            tmp.GioKetThuc = txtGioKetThuc.Text()
            tmp.NgayChieu = dtpNgayChieu.Value.Date()
            tmp.TenPhim = cbxTenPhim.SelectedValue.ToString()
            tmp.MaPhongChieu = cbxMaPhongChieu.SelectedValue.ToString()
            tmp.GiaVe = txtGiaVe.Text()
            bus.Update(tmp)
            gvQLSuatChieu_Load()
        End If
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        If (rbMaSuatChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where MaSuatChieu like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rbMaCaChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where MaCaChieu like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rbMaPhongChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where MaPhongChieu like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rbNgayChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where NgayChieu like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rbPhim.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where TenPhim like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        End If
    End Sub





    Private Sub cbxNgayChieu_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxNgayChieu.SelectedIndexChanged
        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        Dim str As String = ""
        If (cbxNgayChieu.Text = "Tất cả") Then
            str = "select * from SUATCHIEU"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        Else
            str = "select * from SUATCHIEU where NgayChieu like '%" + cbxNgayChieu.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        End If
    End Sub



    'Quan ly ve
    '..........................................
    Public Sub gvVe_Load()
        Dim bus As VeBUS = New VeBUS()
        gvVe.DataSource = bus.GetTable("select * from VE")
    End Sub
    Private Sub cbxQLTenPhim_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxQLTenPhim.SelectedIndexChanged
        Dim bus As VeBUS = New VeBUS()
        Dim str As String = "select VE.MaVe, VE.MaSuatChieu, VE.GiaVeBan, VE.IDThanhVien, VE.VeDat, VE.SoHang, VE.SoDay from VE, SUATCHIEU where VE.MaSuatChieu = SUATCHIEU.MaSuatChieu and SUATCHIEU.TenPhim like '%" + cbxQLTenPhim.SelectedValue.ToString() + "%'"

        gvVe.DataSource = bus.GetTable(str)
        lbSLVe.Text = gvVe.RowCount
    End Sub
    Private Sub cbxLoaiVe_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxLoaiVe.SelectedIndexChanged
        Dim bus As VeBUS = New VeBUS()
        Dim str As String = ""
        If cbxLoaiVe.Text = "Tất cả" Then
            str = "select * from VE"
            gvVe.DataSource = bus.GetTable(str)
        ElseIf (cbxLoaiVe.Text = "Vé đặt") Then
            str = "select * from VE where VeDat=True"
            gvVe.DataSource = bus.GetTable(str)
        ElseIf (cbxLoaiVe.Text = "Vé mua") Then
            str = "select * from VE where VeDat=False"
            gvVe.DataSource = bus.GetTable(str)
        End If
        lbSLVe.Text = gvVe.RowCount
    End Sub


    Private Sub btnTimVe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimVe.Click
        If (rdTimMaVe.Checked = True) Then
            Dim bus As VeBUS = New VeBUS()
            Dim str As String = "select * from VE where MaVe like '%" + txtTimVe.Text + "%'"
            gvVe.DataSource = bus.GetTable(str)
            lbSLVe.Text = gvVe.RowCount - 1
        ElseIf (rsTimTheoPhongChieu.Checked = True) Then
            Dim bus As VeBUS = New VeBUS()
            Dim str As String = "select VE.MaVe, VE.MaSuatChieu, VE.GiaVeBan, VE.IDThanhVien, VE.VeDat, VE.SoHang, VE.SoDay from VE, SUATCHIEU where VE.MaSuatChieu = SUATCHIEU.MaSuatChieu and SUATCHIEU.MaPhongChieu like '%" + txtTimVe.Text + "%'"
            gvVe.DataSource = bus.GetTable(str)
            lbSLVe.Text = gvVe.RowCount - 1
        ElseIf (rdTimTheoNgay.Checked = True) Then
            Dim bus As VeBUS = New VeBUS()
            Dim str As String = "select VE.MaVe, VE.MaSuatChieu, VE.GiaVeBan, VE.IDThanhVien, VE.VeDat, VE.SoHang, VE.SoDay from VE, SUATCHIEU where VE.MaSuatChieu = SUATCHIEU.MaSuatChieu and SUATCHIEU.NgayChieu like '%" + txtTimVe.Text + "%'"
            gvVe.DataSource = bus.GetTable(str)
            lbSLVe.Text = gvVe.RowCount - 1
        ElseIf (rdTimTheoSuatChieu.Checked = True) Then
            Dim bus As VeBUS = New VeBUS()
            Dim str As String = "select * from VE where MaSuatChieu like '%" + txtTimVe.Text + "%'"
            gvVe.DataSource = bus.GetTable(str)
            lbSLVe.Text = gvVe.RowCount
        End If
    End Sub


    Private Sub lbDangXuat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbDangXuat.Click
        Frm_Login.txtTenDN.Text = ""
        Frm_Login.txtMatKhau.Text = ""
        Frm_Login.txtTenDN.Select()
        Close()
    End Sub

    Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
        Dim dlg As OpenFileDialog = New OpenFileDialog()
        Dim FileToCopy As String = ""
        Dim NewCopy As String = ""

        dlg.Filter = "Chon tap tin .mdb|*.mdb"
        If (dlg.ShowDialog() = DialogResult.OK) Then
            FileToCopy = dlg.FileName
        End If

        NewCopy = Application.StartupPath() + "\" + IO.Path.GetFileName(FileToCopy)

        If System.IO.File.Exists(FileToCopy) = True Then

            System.IO.File.Copy(FileToCopy, NewCopy)

        End If

        MessageBox.Show("Kết nối dữ liệu thành công!!!")
    End Sub

    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Dim dlg As FolderBrowserDialog = New FolderBrowserDialog()
        Dim str As String = ""
        If (dlg.ShowDialog() = DialogResult.OK) Then
            str = dlg.SelectedPath()
        End If
        Dim f As FileInfo = New FileInfo(Application.StartupPath() + "\RAPCHIEUPHIM.mdb")
        f.CopyTo(str + "\RAPCHIEUPHIM_" + Now.ToString("yyyy_MM_dd_hh_mm") + ".mdb")
        MessageBox.Show("Sao lưu dữ liệu thành công!!!")
    End Sub

    
    Private Sub help_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles help1.Click
        Help.ShowHelp(Me, Application.StartupPath() + "\HuongDan.chm")
    End Sub
End Class